﻿using Alison.EFCore.Dto;
using Alison.Service;
using Alison.Tools.HttpContact.Response;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Alison.API.Controllers
{
    /// <summary>
    /// 菜单数据控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class MenuController : ControllerBase
    {
        private readonly IMenuService _service;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="service"></param>
        public MenuController(IMenuService service)
        {
            this._service = service;
        }


        /// <summary>
        /// 获取菜单列表
        /// </summary> 
        /// <returns>结果</returns>
        [HttpPost]
        public async Task<ApiResponse> Save([FromBody] MenuDto dto) => await _service.Save(dto);
         
        /// <summary>
        /// 获取菜单列表
        /// </summary> 
        /// <returns>结果</returns>
        [HttpGet]
        public async Task<ApiResponse> GetAll() => await _service.GetAll();
        /// <summary>
        /// 获取菜单列表
        /// </summary> 
        /// <returns>结果</returns>
        [HttpPost]
        public async Task<ApiResponse> GetAll([FromBody] MenuDto dto) => await _service.GetAll(dto);

        /// <summary>
        /// 新增菜单
        /// </summary> 
        /// <returns>结果</returns>
        [HttpPost]
        public async Task<ApiResponse> Add([FromBody] MenuDto dto) => await _service.Add(dto);

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="id">用户ID</param>
        /// <returns>结果</returns>
        [HttpDelete("{id}")]
        public async Task<ApiResponse> Delete(int id) => await _service.Delete(id);
    }
}
